package cn.zyjw.controller;

import cn.zyjw.domain.UserBank;
import cn.zyjw.model.R;
import cn.zyjw.service.UserBankService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Api("用户银行卡管理")
@RestController
@RequestMapping("/userBanks")
public class UserBankController {

    @Autowired
    private UserBankService userBankService;


    @GetMapping
    @ApiOperation("用户银行卡分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "current", value = "当前页"),
            @ApiImplicitParam(name = "size", value = "每页展示条数"),
            @ApiImplicitParam(name = "usrId", value = "用户id", required = true, dataType = "Long"),
    })
    public R<Page<UserBank>> findByPage(Page<UserBank> page, @RequestParam Long usrId) {

        page.addOrder(OrderItem.desc("last_update_time"));
        Page<UserBank> bankPage = userBankService.page(page,
                new LambdaQueryWrapper<UserBank>()
                        .eq(UserBank::getUserId, usrId)
        );
        return R.ok(bankPage);
    }
}
